package demo1107.demo02;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/11/7 10:33
 */
public class Test01 {
    public static void main(String[] args) {
        Singleton i1 = Singleton.getInstance();
        Singleton i2 = Singleton.getInstance();

        System.out.println(i1);
        System.out.println(i2);
    }
}
 class Singleton{
    //1.构造方法私有化
    private Singleton(){}

    //2.声明一个静态的苯类对象----饿汉式
    private static Singleton singleton = new Singleton();

    //3.提供一个静态的方法返回本类对象
    public static Singleton getInstance(){
        return singleton;
    }
}
